#!/bin/sh
echo "obsoleting";
exit;
if [ "$1port" = "port" ]; then
    echo "need start prot"
    exit
fi

if [ "$2port" = "port" ]; then
    echo "need end prot"
    exit
fi
# docker ps -a|grep redis_cluster |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
# docker ps -a|grep redis_cluster |awk '{print $1}'|xargs docker rm >/dev/null 2>&1

# /usr/local/etc/redis/redis.conf


# 修改文件权限
# find 60*/data|grep -v git|xargs sudo chown 100:101


replicas=""
for port in `seq $1 $2`
do

    docker ps -a|grep redis_cluster$port |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
    docker ps -a|grep redis_cluster$port |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
    dir=~/workspace/dockers/wuhua/redis-cluster/$port/data
    replicas="$replicas 10.0.7.29:$port"

    if [ ! -d "$dir" ];then
        mkdir $dir
    fi
    sudo chown 100:101 $dir

    docker run \
    -d \
    --user redis\
    --name redis_cluster$port \
    -p $port:$port \
    --net host \
    --restart=always \
    -v $dir:/data \
    -v ~/workspace/dockers/wuhua/redis-cluster/$port/redis.conf:/cluster/redis.conf \
    wolferhua/redis:4 redis-server /cluster/redis.conf
done
# docker run  -it  wolferhua/redis:4 /cluster/redis-trib.rb create --replicas 1 $replicas

# sudo chown wolferhua:wolferhua 60* -Rf
# find |grep nodes|xargs sudo rm
# docker run  -it  wolferhua/redis:4 redis-cli -c -h 10.0.7.29 -p 6001

echo  "docker run  -it  wolferhua/redis:4 /cluster/redis-trib.rb create --replicas 1 $replicas"